package com.miao.controller;

import com.miao.base.exception.XueChengPlusException;
import com.miao.base.model.RestResponse;
import com.miao.dto.MediaConditionDto;
import com.miao.pojo.MediaFiles;
import com.miao.service.IMediaFilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/open")
public class MediaOpenController {
    @Autowired
    private IMediaFilesService mediaFilesService;

    //看视频的时候获取url
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getUrlOfVideo(@PathVariable String mediaId){
        MediaFiles mediaFiles = mediaFilesService.getById(mediaId);
        if(mediaFiles == null || mediaFiles.getUrl() == null){
            XueChengPlusException.cast("视频文件不存在或等待转码中......");
        }
        String url = mediaFiles.getUrl();
        return RestResponse.success(url);
    }
}
